package org.lq.er.view.score;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import org.lq.er.entity.Score_info;
import org.lq.er.entity.Student;
import org.lq.er.entity.Subject;
import org.lq.er.service.Score_infoService;
import org.lq.er.service.SubjectService;
import org.lq.er.service.impl.Score_infoServiceImpl;
import org.lq.er.service.impl.SubjectServiceImpl;

import javax.swing.JLabel;
import javax.swing.JTextField;
/**
 * 成绩显示视图
 * @author 宋铀
 * 
 * @package org.lq.er.view.score
 * @date 2020年8月24日下午8:27:56
 */
public class ER_score extends JFrame {

	private JPanel contentPane;
	private JTextField text_cardId;
	private JTextField text_subject;
	private JTextField text_score;
	private static Student student = null;
	private Score_infoService score_infoService = new Score_infoServiceImpl();
	private SubjectService subjectService = new SubjectServiceImpl();
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ER_score frame = new ER_score(student);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ER_score(Student student) {
		this.student = student;
		setTitle("成绩");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 347, 260);
		setLocationRelativeTo(null);
		contentPane = new JPanel();
		contentPane.setBackground(Color.white);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		JLabel lbl_cardId = new JLabel("身份证号:");
		lbl_cardId.setBounds(63, 47, 54, 15);
		panel.add(lbl_cardId);
		
		
		JLabel lbl_subject = new JLabel("科目:");
		lbl_subject.setBounds(63, 94, 54, 15);
		panel.add(lbl_subject);
		
		JLabel lbl_score = new JLabel("成绩;");
		lbl_score.setBounds(63, 146, 54, 15);
		panel.add(lbl_score);
		
		text_cardId = new JTextField();
		text_cardId.setEditable(false);
		text_cardId.setBounds(127, 44, 111, 21);
		panel.add(text_cardId);
		text_cardId.setColumns(10);
		
		text_subject = new JTextField();
		text_subject.setEditable(false);
		text_subject.setBounds(127, 91, 111, 21);
		panel.add(text_subject);
		text_subject.setColumns(10);
		
		text_score = new JTextField();
		text_score.setEditable(false);
		text_score.setBounds(127, 143, 111, 21);
		panel.add(text_score);
		text_score.setColumns(10);
		init(student);
	}
	
	// 给组件赋值
	public void init(Student student) {
		text_cardId.setText(student.getCard_id());
		// 获取成绩信息
		
		Score_info score_info = score_infoService.getByStu_id(String.valueOf(student.getStu_no()));
		System.out.println(student.getCard_id());
		// 获取科目名称
		int num = score_info.getSubject_id();// 成绩信息里的科目编号
		Subject subject = subjectService.findById(num); // 获取科目对象
		String subjectName = subject.getSubjectName(); // 获取科目名称
		text_subject.setText(subjectName);
		text_score.setText(score_info.getScore()+"");
		
	}
	

}
